package com.cloudwise.controller;

import com.cloudwise.dao.EmpDao;
import com.cloudwise.entity.Emp;
import com.cloudwise.service.EmpService;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

/**
 * @author ：Teacher陈（86521760@qq.com）
 * @date ：Created in 2021/11/18 10:47
 * @description：员工控制器
 * @modified By：
 * @version: 1.0
 */
/*@WebServlet(urlPatterns = "/emp")
public class EmpController extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("servlet开始执行了");
        //此处的代码有问题，每一个请求对应一份独立的spring容器，性能严重下降，
        //理想状态下，全局只保存一份spring容器，所有的请求/servlet共享
        *//*ClassPathXmlApplicationContext applicationContext= new ClassPathXmlApplicationContext("applicationContext.xml");*//*
        //从servlet容器中获取spring容器
        ClassPathXmlApplicationContext applicationContext = (ClassPathXmlApplicationContext) getServletContext().getAttribute("applicationContext");
        EmpService empServiceImpl = applicationContext.getBean("empServiceImpl", EmpService.class);
        List<Emp> empList = empServiceImpl.findAllEmp();
        HttpSession session = req.getSession();
        session.setAttribute("empList",empList);
        req.getRequestDispatcher("showEmp.jsp").forward(req,resp);


    }
}*/
